;;; init.el -*- lexical-binding: t; -*-

(load (concat (file-name-directory load-file-name)
              "lisp/const.el")
      nil (not init-file-debug))
(load (concat (file-name-directory load-file-name)
              "lisp/load-paths.el")
      nil (not init-file-debug))

(when (version< emacs-version canary-emacs-min-version)
  (error (concat "Your version of Emacs (%s) is too old.\n"
                 "Canary requires Emacs version %s or above.")
         emacs-version canary-emacs-min-version))



;;----------------------------------------------------------------------
;; Speed up startup, avoid garbage collection
;;----------------------------------------------------------------------
;; https://www.reddit.com/r/emacs/comments/3kqt6e/2_easy_little_known_steps_to_speed_up_emacs_start/
(let ((default-file-name-handler-alist file-name-handler-alist)
      (default-gc-cons-threshold gc-cons-threshold))
  (setq file-name-handler-alist nil)
  (setq gc-cons-threshold most-positive-fixnum)
  (add-hook 'emacs-startup-hook
            (lambda ()
              "Restore defalut values after init."
              (setq file-name-handler-alist default-file-name-handler-alist)
              (setq gc-cons-threshold default-gc-cons-threshold)
              (if (boundp 'after-focus-change-function)
                  (add-function :after after-focus-change-function
                                (lambda ()
                                  (unless (frame-focus-state)
                                    (garbage-collect))))
                (add-hook 'focus-out-hook 'garbage-collect)))))



;;----------------------------------------------------------------------
;; Core config
;;----------------------------------------------------------------------
(require 'init-func)
(require 'init-custom)
(require 'init-package)
(require 'init-basic)
(require 'init-exec-path)               ; Setup $PATH



;;----------------------------------------------------------------------
;; UI config
;;----------------------------------------------------------------------
(require 'init-frame)
(require 'init-theme)
(require 'init-linum)
